# -*- coding: utf8 -*-
import unittest
from tmap import Map
from human import Player,Human,Priest,Warrior,Hunter,Factory
class TestWarrior(unittest.TestCase):
    def test_warrior(self):
        ppl = Player(mhp=50,hp=50)    #2名战士
        ppl2 = Player(mhp=50,hp=50)
        mymap = Map([[ppl,ppl2]])
        mymap.missionStart()
        mymap.mapRoundStart()
        ppl.comboAttack(ppl2)         #测试连击效果
        print ppl2.hp
        self.assertEqual(ppl2.hp,40)  #连续受到2次攻击伤害
    def test_priest (self):
        ppl3 = Factory.new(Priest,hp=50,mhp=50)
        print dir(ppl3)
        ppl4 = Player(mhp=50,hp=10)
        ppl5 = Player(mhp=50,hp=10)
        ppl6 = Player(mhp=50,hp=10)
        mymap2 = Map([[ppl3,ppl4,0,0,0,0],  #强效治疗只能加到4号，快速治疗可以加到4，5号，远程治疗可加4，5，6号
                      [0,ppl5,0,0,0,0],
                      [0,0,0,0,0,0,],
                      [0,0,0,0,0,ppl6]])
        mymap2.missionStart()
        mymap2.mapRoundStart()
        self.assertEqual(ppl3.powerTreatment(ppl5),False) #超过距离加不到
        ppl3.fastTreatment(ppl5)   
        self.assertEqual(ppl5.hp,35)   #测试快速治疗的治疗效果
        mymap2.mapRoundStart()
        ppl3.powerTreatment(ppl4)
        self.assertEqual(ppl4.hp,50)
        mymap2.mapRoundStart()
        ppl3.fastTreatment(ppl5)
        self.assertEqual(ppl5.hp,50)   #测试过量治疗
        self.assertEqual(ppl3.powerTreatment(ppl4),False) #测试行为值不足，无法使用技能
        mymap2.mapRoundStart()
        ppl3.farTreatment(ppl6)
        self.assertEqual(ppl6.hp,22)  #测试远距离治疗 和治疗量取整
    def test_hunter (self):
        ppl_Lr= Factory.new(Hunter,hp=50,mhp=50)    #1个猎人，2个炮灰
        ppl7 = Player(mhp=50,hp=50)
        ppl8 = Player(mhp=50,hp=50)
        mymap3 = Map([[ppl_Lr,0,0,0,0],
                       [0,ppl7,0,0,0],
                       [0,0,0,0,ppl8]])
        mymap3.missionStart()                     #测试游戏开始
        mymap3.mapRoundStart()
        self.assertEqual(ppl_Lr.shoot(ppl8),False)   #测试攻击距离
        ppl_Lr.shoot(ppl7)
        self.assertEqual(ppl7.hp,45)              #测试射击伤害
        miss=0                                    #测试远距离射击的命中率
        for i in range(1,1000):
            mymap3.mapRoundStart()
            ppl_Lr.farShoot(ppl8)
            if ppl8.hp != 50:
                miss += 1
                ppl8.hp=50
        print miss
        self.assertEqual(miss>450,True)
        self.assertEqual(miss<750,True)
if __name__ == '__main__':
    unittest.main()
